package com.code.wflow.service.impl;

import com.code.wflow.mapper.InstanceNodeDetailMapper;
import com.code.wflow.model.InstanceNodeDetail;
import com.code.wflow.service.InstanceNodeDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 流程实例节点详情(WorkflowInstanceNodeDetail)表服务层
 *
 * @author ggh
 * @date 2022/11/10
 */
@Service
public class InstanceNodeDetailServiceImpl implements InstanceNodeDetailService {
    @Autowired
    private InstanceNodeDetailMapper instanceNodeDetailMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public InstanceNodeDetail queryById(Long id) {
        return this.instanceNodeDetailMapper.queryById(id);
    }

    /**
     * 通过实例id查询多条数据
     *
     * @param instanceId 主键
     * @return 实例对象
     */
    @Override
    public List<InstanceNodeDetail> queryByInstanceId(Long instanceId) {
        return this.instanceNodeDetailMapper.queryByInstanceId(instanceId);
    }

    /**
     * 通过节点查询多条数据
     *
     * @param instanceNodeId 主键
     * @return 实例对象
     */
    @Override
    public List<InstanceNodeDetail> queryByInstanceNode(Long instanceNodeId) {
        return this.instanceNodeDetailMapper.queryByInstanceNode(instanceNodeId);
    }


    /**
     * 通过节点查询状态
     *
     * @param instanceNodeId 主键
     * @return 实例对象
     */
    @Override
    public List<Byte> queryStatusByInstanceNode(Long instanceNodeId) {
        return this.instanceNodeDetailMapper.queryStatusByInstanceNode(instanceNodeId);
    }

    /**
     * 修改数据
     *
     * @param workflowInstanceNodeDetail 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(InstanceNodeDetail workflowInstanceNodeDetail) {
        return this.instanceNodeDetailMapper.update(workflowInstanceNodeDetail) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.instanceNodeDetailMapper.deleteById(id) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param idList 主键
     * @return 是否成功
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByIdList(List<Long> idList) {
        if (this.instanceNodeDetailMapper.deleteByIdList(idList) == idList.size()) {
            return true;
        }
        throw new RuntimeException();
    }
}
